<template>
  <div class="v-workflow-step">
    <template v-if="data.length>0">
      <!-- <van-steps direction="vertical" :active="activeStep!=null?activeStep:activeStepNow"> -->
      <van-steps direction="vertical" :active="data.length">
        <van-step v-for="(item,index) in data" :key="'workflowIndex'+index">
          <template v-slot:inactive-icon>
            <van-icon name="success" class="is-success" v-if="item.isActive==2"/>
            <div class="is-waiting" v-if="item.isActive==0"></div>
            <div class="is-process" v-if="item.isActive==1"></div>
          </template>
          <template v-slot:active-icon>
            <van-icon name="success" class="is-success" v-if="item.isActive==2"/>
            <div class="is-waiting" v-if="item.isActive==0"></div>
            <div class="is-process" v-if="item.isActive==1"></div>
          </template>
          <div class="step-box">
            <span style="margin-bottom: 10px;">{{item[stepName]||'--'}}</span>
            <span v-if="showSubtitle" class="sub-title">{{item[stepDesc]||'--'}}</span>
          </div>
        </van-step>
      </van-steps>
    </template>
    <v-empty v-else description="暂无数据"></v-empty>
  </div>
</template>

<script>
export default {
  name:'',
  props:{
    // 展示的数据
    data:{
      type:Array,
      default: () => {
        return [];
      },
    },
    // 步骤名称
    activeStep:{
      type:Number||String,
    },
    // 步骤名称
    stepName:{
      type:String,
      default:'taskName'
    },
    // 步骤描述
    stepDesc:{
      type:String,
      default:'taskDesc'
    },
    // 是否显示描述
    showSubtitle:{
      type:Boolean,
      default:true
    }
  },
  data () {
    return {
      activeStepNow:0,
    }
  },
  created () {
    this.getActiveStep()
  },
  methods: {
    getActiveStep(){
      if(this.data.length>0){
        for (let i = 0; i < this.data.length; i++) {
          const element = this.data[i];
          if(this.data[i].isActive==0){
            break
          }else if(this.data[i].isActive==2){
            this.activeStepNow++
          }
        }
      }
    },
  },
}
</script>

<style lang="less" scoped>
@deep: ~">>>";
@mainColor:#1990FF; // 步骤条主题颜色
div,span,p{
  word-break: break-all;
}
@{deep}.van-steps{
  padding: 0;
  .van-step{
    color: #61677A;
  }
  .van-step--finish .van-step__circle, .van-step--finish .van-step__line{
    background-color: @mainColor;
  }
  .van-step--vertical::after{
    border: none;
  }
  .van-step--finish,.van-step__title--active{
    color: #333;
  }
  .step-box{
    display: flex;
    flex-direction: column;
    width: 100%;
    font-size: 14px;
    font-weight: 600;
    span{
      &:nth-child(2){
        color: #61677A;
        font-size: 13px;
        font-weight: 400;
        color: #8995AC;
      }
    }
  }
  .van-step__line{
    width: 2px;
    background-color: #BCC5D6;
    top: 22px;
  }
  .van-step--vertical {
    padding: 15px 10px 15px 32px;
    position: relative;
    .van-step__circle-container,.van-step__line{
      left: 12px;
      z-index: 1;
    }
    .van-step__circle-container{
      z-index: 2;
      top: 25px;
    }
    .van-step__title{
      z-index: 3;
      position: relative;
    }
  }
  .is-process{
    border: 4px solid @mainColor;
    width: 10px;
    height: 10px;
    border-radius: 10px;
    background: #fff;
  }
  .is-success{
    width: 16px;
    height: 16px;
    background: #fff;
    border: 1px solid @mainColor;
    text-align: center;
    border-radius: 16px;
    line-height: 18px;
    color: @mainColor;
    font-size: 13px;
  }
  .is-waiting{
    background: #F7FCFF;
    width: 8px;
    height: 8px;
    border: 2px solid #BCC5D6;
    border-radius: 10px;
  }
  .van-step:last-child .van-step__line {
    width: 0!important;
  }
}
</style>